package Graph;

import java.util.*;

public class 建造最大岛屿 {
    static int n;
    static int m;
    static int[][] graph;

    /*public static void main (String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        graph = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                graph[i][j] = in.nextInt();
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (graph[i][j] == 0) {
                    graph[i][j] = 1;
                    res = Math.max(res, dfs(i, j, new boolean[n][m]));
                    graph[i][j] = 0;
                }
            }
        }
        res = Math.max(res, dfs(0, 0, new boolean[n][m]));
        System.out.println(res);
    }

    private static int dfs(int i, int j, boolean[][] visited) {
        if (i < 0 || i >= n || j < 0 || j >= m || visited[i][j] || graph[i][j] == 0) {
            return 0;
        }
        visited[i][j] = true;
        return 1 + dfs(i + 1, j, visited) + dfs(i, j + 1, visited) + dfs(i - 1, j, visited) + dfs(i, j - 1, visited);
    }*/

    // 对每个岛屿进行标记
    static int mark;
    static int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    // DFS 进行搜索，将每个岛屿标记为不同的数字
    public static int dfs(int x, int y, boolean[][] visited) {
        if (x < 0 || x >= m || y < 0 || y >= n) return 0;
        if (visited[x][y] || graph[x][y] == 0) return 0;
        visited[x][y] = true;
        graph[x][y] = mark;
        return 1 + dfs(x, y + 1, visited) + dfs(x, y - 1, visited) + dfs(x + 1, y, visited) + dfs(x - 1, y, visited);
    }

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        m = sc.nextInt();
        n = sc.nextInt();
        graph = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                graph[i][j] = sc.nextInt();
            }
        }
        // 初始化mark变量，从2开始（区别于0水，1岛屿）
        mark = 2;
        // 定义一个HashMap，记录某片岛屿的标记号和面积
        Map<Integer, Integer> getSize = new HashMap<>();
        // 定义一个HashSet，用来判断某一位置水四周是否存在不同标记编号的岛屿
        Set<Integer> set = new HashSet<>();
        // 定义一个boolean变量，看看DFS之后，是否全是岛屿
        boolean isAllIsland = true;
        // 遍历二维数组进行DFS搜索，标记每片岛屿的编号，记录对应的面积
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (graph[i][j] == 0) isAllIsland = false;
                if (graph[i][j] == 1) {
                    getSize.put(mark, dfs(i, j, new boolean[m][n]));
                    mark++;
                }
            }
        }
        int result = 0;
        if (isAllIsland) result =  m * n;
        // 判断每个水位置四周是否有岛屿，并记录下四周不同相邻岛屿面积之和
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (graph[i][j] == 0) {
                    set.clear();
                    // 当前水位置变更为岛屿，所以初始化为1
                    int curSize = 1;
                    for (int[] dir : dirs) {
                        int curRow = i + dir[0];
                        int curCol = j + dir[1];
                        if (curRow < 0 || curRow >= m || curCol < 0 || curCol >= n) continue;
                        int curMark = graph[curRow][curCol];
                        // 如果当前相邻的岛屿已经遍历过或者HashMap中不存在这个编号，继续搜索
                        if (set.contains(curMark) || !getSize.containsKey(curMark)) continue;
                        set.add(curMark);
                        curSize += getSize.get(curMark);
                    }
                    result = Math.max(result, curSize);
                }
            }
        }
        System.out.println(result);
    }
}
